/* poporca2.p - PO RECEIPT OF WORK ORDER SUBCONTRACT                    */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: poporca2.p 34425 2013-08-30 11:58:48Z aew                         $: */
/* REVISION: 7.3     LAST MODIFIED: 04/19/93    BY: tjs *G964**/
/* REVISION: 7.4     LAST MODIFIED: 01/12/94    BY: qzl *H276**/
/* REVISION: 7.5     LAST MODIFIED: 08/09/94    BY: tjs *J014**/
/* REVISION: 7.3     LAST MODIFIED: 10/20/94    BY: dpm *FS27*          */
/* REVISION: 7.3     LAST MODIFIED: 11/17/94    BY: bcm *GO37*          */
/* REVISION: 8.5     LAST MODIFIED: 11/20/96    BY: *J191* Suresh Nayak */
/* REVISION: 9.0     LAST MODIFIED: 04/16/99    BY: *J2DG* Reetu Kappor */
/* Old ECO marker removed, but no ECO header exists *F0PN*               */
/* REVISION: 9.1      LAST MODIFIED: 07/05/00   BY: Strip/Beautify:  3.0 */
/* REVISION: 9.1      LAST MODIFIED: 06/15/00   BY: Zheng Huang *N0DK*   */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb           */
/* $Revision: 1.14 $    BY: Dan Herman   DATE: 11/04/04  ECO: *M1V1*  */

/* GROUPED MULTIPLE FIELD ASSIGNMENTS INTO ONE AND ADDED NO-UNDO          */
/* WHEREVER MISSING AND REPLACED FIND STATEMENTS WITH FOR FIRST           */
/* STATEMENTS FOR ORACLE PERFORMANCE                                      */

{us/bbi/mfdeclre.i}
/* SEVERITY PREPROCESSOR CONSTANT DEFINITION INCLUDE FILE */
{us/px/pxmaint.i}

define output parameter p_prompt    as   character   no-undo.
define shared variable wolot        like pod_wo_lot  no-undo.
define shared variable woop         like pod_op      no-undo.
define shared variable pod_recno    as   recid.
define shared variable rct_site     like pod_site.
define shared variable undo_all like mfc_logical.
define variable yn                  like mfc_logical no-undo.

define variable vWorkOrderLotExist  like mfc_logical no-undo.
define variable vWorkOrderRouteExist  like mfc_logical no-undo.
define variable lLegacyAPI          as logical no-undo.
define variable l_errlevel          as integer no-undo.
{us/mf/mfaimfg.i}  /* Common API constants and variables */

{us/po/popoit01.i} /* Define API purchase order temp tables  */
{us/mf/mfctit01.i} /* Define API transaction comments temp tables */

p_prompt = "".

if c-application-mode = "API" then do:
   {us/bbi/gprun.i ""gpaigach.p"" "(output ApiMethodHandle)"}
   
   if valid-handle(ApiMethodHandle) then do:
      lLegacyAPI = false.
   end.
   else do:
      lLegacyAPI = true.
      /* Get handle of API controller */
      {us/bbi/gprun.i ""gpaigh.p"" "(output ApiMethodHandle,
                              output ApiProgramName,
                              output ApiMethodName,
                              output ApiContextString)"}

      /* Get current purchase order transaction detail record */
      run getPurchaseOrderTransDetRecord in ApiMethodHandle
         (buffer ttPurchaseOrderTransDet).
   end.
end. /* IF c-application-mode = "API" */

/*MAIN-BEGIN*/
/*MAIN-END*/

/*@TO-DO  need find pod_det in control*/
find pod_det where recid(pod_det) = pod_recno exclusive-lock.
/*@TO-DOEND*/

{us/px/pxrun.i &PROC='processRead' &PROGRAM='wowoxr.p'
         &PARAM="(input  wolot,
                  buffer wo_mstr,
                  input  {&NO_LOCK_FLAG},
                  input  {&NO_WAIT_FLAG})"
         &NOAPPERROR=True
         &CATCHERROR=True
}

{us/px/pxrun.i &PROC='validateSubcontractWorkOrder' &PROGRAM='porcxr1.p'
         &PARAM="(buffer wo_mstr,
                  input  pod_part,
                  input  pod_project,
                  input  woop,
                  output vWorkOrderLotExist)"
         &NOAPPERROR=True
         &CATCHERROR=True
}
if     return-value <> {&SUCCESS-RESULT}
   and return-value <> {&WARNING-RESULT}
then do:
   assign
      undo_all = true
      p_prompt = "wolot".
   leave.
end. /* IF RETURN-VALUE <> {&SUCCESS-RESULT} and ... */

if vWorkOrderLotExist then do:
   if index ("FPC",wo_status) = 0 then
      rct_site = wo_site.

   {us/px/pxrun.i &PROC='defaultSubcontractOperation' &PROGRAM='porcxr1.p'
            &PARAM="(input-output woop)"
            &NOAPPERROR=True
            &CATCHERROR=True
   }

   {us/px/pxrun.i &PROC='readOperationForFirstWOID' &PROGRAM='wowrxr.p'
            &PARAM="(input  wolot,
                     input  woop,
                     buffer wr_route,
                     input  {&NO_LOCK_FLAG},
                     input  {&NO_WAIT_FLAG})"
            &NOAPPERROR=True
            &CATCHERROR=True
   }

   {us/px/pxrun.i &PROC='validateSubcontractOperation' &PROGRAM='porcxr1.p'
            &PARAM="(buffer wr_route,
                     input  wo_status,
                     input  wo_type,
                     input  wo_nbr)"
            &NOAPPERROR=True
            &CATCHERROR=True
   }

   if     return-value <> {&SUCCESS-RESULT}
      and return-value <> {&WARNING-RESULT}
   then do:
      assign
         undo_all = true
         p_prompt = "woop".
      leave.
   end. /* IF RETURN-VALUE <> {&SUCCESS-RESULT} and ... */

   /*@TO-DO - controller will need to execute this function along with
   check against UI control flag*/ /*mxb*/
   /*@TO-DOEND*/

   if {us/px/pxfunct.i &FUNCTION='isSubcontractOperationMissing' &PROGRAM='wowrxr.p'
                 &PARAM="input (available wr_route),
                         input wo_status"
      } and
      not {us/px/pxfunct.i &FUNCTION='isRepetitiveProduction' &PROGRAM='rewoxr.p'
                     &PARAM="input wo_type,
                             input wo_nbr"
      }
   then do:
      yn = no.
      if c-application-mode = "API"  and lLegacyAPI then
         assign {us/mf/mfaiset.i yn ttPurchaseOrderTransDet.addWoOperation}.

      /* MESSAGE #106 - OPERATION DOES NOT EXIST */
      {us/bbi/pxmsg.i
         &MSGNUM=106
         &ERRORLEVEL={&APP-ERROR-RESULT}}

      assign






         undo_all = true
         p_prompt = "woop".
      leave.
   end. /* IF {pxfunct.i &FUNCTION='isSubcontractOperationMissing' */
   else do:
      {us/px/pxrun.i &PROC='CheckIfOperationMatchesthePO' &PROGRAM='porcxr1.p'
                     &PARAM="(buffer pod_det,
                              input  woop)"
                     &NOAPPERROR=True
                     &CATCHERROR=True
      }
      if return-value <> {&SUCCESS-RESULT}
      then do:
         /* MESSAGE #20049 - ROUTING OPERATION DOES NOT MATCH THE OPERATION ENTERED ON THE PO */
         {us/bbi/gprun.i ""gpcfmsg.p"" "(input 20049,
                                         input 0,
                                         input program-name(1),
                                         input '',
                                         input '',
                                         input '',
                                         input false,
                                         output l_errlevel)"}
         if l_errlevel <> 0
         then do:
            {us/bbi/pxmsg.i &MSGNUM=20049 &ERRORLEVEL=l_errlevel}

            if c-application-mode <> "API"
               and not batchrun
               and l_errlevel < 3
            then
               pause.

         end. /* IF l_errlevel <> 0 */
         if l_errlevel > 2
         then do:
            assign
               undo_all = true
               p_prompt = "woop".
            leave.
         end. /* IF l_errlevel > 2  */
      end. /* IF return-value <> {&SUCCESS-RESULT} */
   end. /* ELSE ( IF {us/px/pxfunct.i &FUNCTION='isSubcontractOperationMissing' ) DO */
end. /*else (if not vWorkOrderLotExist) do*/

{us/px/pxrun.i &PROC='setSubcontractOperation' &PROGRAM='porcxr1.p'
         &PARAM="(buffer pod_det,
                  input  wolot,
                  input  woop)"
         &NOAPPERROR=True
         &CATCHERROR=True
}
